#include <iostream>
#include <fstream>
#include <ctime>

using namespace std;
int numbers[5000];

void bubbleSort(int arr[])
{
    for (size_t i = 0; i < 4999; i++)
    {
        bool sorted = true;
        for (size_t j = 0; j < 4999 - i; j++)
        {
            if (arr[j] > arr[j + 1])
            {
                sorted = false;
                int temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }

        }
        if (sorted) return;
    }
}

void readFile(string fileName)
{
    ifstream file(fileName);
    if (file.is_open())
    {
        for (size_t i = 0; i < 5000; i++)
        {
            file >> numbers[i];
        }
    }
    else cout << "Fail open: " << fileName;    
    file.close();
    clock_t start = clock();
    bubbleSort(numbers);
    clock_t end = clock();
    cout << fileName << " " << end - start << " milliseconds" << endl;
} 

int main()
{
    readFile("m1_sorted.txt");
    readFile("m2_reverse.txt");
    readFile("m3_shuffle.txt");
}
